package cn.iot.controller.sys;

import cn.iot.common.api.CommonResult;
import cn.iot.sys.entity.SysNotice;
import cn.iot.sys.service.SysNoticeService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/sys/notice")
public class SysNoticeController {

    @Autowired
    private SysNoticeService sysNoticeService;

    @ApiOperation("查询最新的一条未读通知")
    @GetMapping("/getOneSysNotice")
    public CommonResult<SysNotice> getOneSysNotice() {
        SysNotice sysNoticeList = sysNoticeService.getOneSysNotice();
        return CommonResult.success(sysNoticeList);
    }

    @ApiOperation("修改通知为已读")
    @PostMapping("/updateNoticeStatus")
    public CommonResult<Integer> updateNoticeStatus(@RequestBody SysNotice sysNotice) {
        Integer num = sysNoticeService.updateNoticeStatus(sysNotice);
        if(num>0){
            return CommonResult.success();
        }
        return CommonResult.failed();
    }
}
